package com.xbongbong.pro.enums.fund.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 生成规则枚举
 * @author: 汪腾伟
 * @date: 2020/8/4
 * @desrcption: 资金模块模式规则枚举码
 * @version:1.0
 */
@Getter
public enum ModelTypeEnum {

    /**
     * 生成规则：1手动创建应收，2按开票产生应收，3按出库产生应收
     * 资金3.0先开发前两种模式
     */
    PLAN(1L,"enum.modelType.name.plan", XbbRefTypeEnum.PAYMENT),
    INVOICE(2L,"enum.modelType.name.invoice", XbbRefTypeEnum.INVOICE),
    OUTSTOCK(3L,"enum.modelType.name.outstock", XbbRefTypeEnum.CONTRACT_OUTSTOCK),
    ;

    /**
     * 模式code
     */
    private Long code;

    /**
     * 模式名称
     */
    private String name;

    /**
     * 业务类型
     */
    private XbbRefTypeEnum xbbRefTypeEnum;


    ModelTypeEnum(Long code, String name, XbbRefTypeEnum xbbRefTypeEnum){
        this.code = code;
        this.name = name;
        this.xbbRefTypeEnum = xbbRefTypeEnum;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getI18nName() {
        return name;
    }

    /**
     * 根据code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.fund.enums.ModelTypeEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static ModelTypeEnum getByCode(Long code) {
        for (ModelTypeEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        return null;
    }

    /**
     * 根据code获取模式名称，为空则默认返回“手动创建应收”模式
     * @param code
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static String getNameByCode(Long code) {
        for (ModelTypeEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache.getName();
            }
        }
        return PLAN.getName();
    }
}
